<template>
  <div>
    <el-form>
      <el-form-item label="名称">
        <el-input v-model="advertDate.name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="$emit('cancel')">取消</el-button>
        <el-button type="primary"
                   @click="onSubmit">确认</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import Vue from 'vue'
import { saveOrUpdate } from '@/services/advert-space'

export default Vue.extend({
  name: 'AdvertSpaceEdit',
  props: {
    advert: {
      type: [Object]
    },
    isEdit: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      advertDate: {
        name: ''
      }
    }
  },

  created() {
    if (this.isEdit) {
      this.advertDate = this.advert
    }
  },

  methods: {
    async loadResource() {
      // const { data } = await getResourceCategories()
      // this.resource = data.data
    },

    async onSubmit() {
      if (this.isEdit) {
        await saveOrUpdate(this.advert)
      } else {
        await saveOrUpdate(this.advertDate)
      }
      this.$message.success('操作成功')
      this.$emit('success')
    }
  }
})
</script>

<style lang="scss" scoped></style>
